﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataTransferObject;

namespace JSKE
{
    public partial class NewWHDlg : FormLang
    {
        public WorkingHourItem WHI;

        List<WorkingHourItem> listOfWHItems;

        public NewWHDlg(List<WorkingHourItem> listWHI)
        {
            //InitializeComponent();

            this.listOfWHItems = listWHI;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (txtWHName.Text.Equals(string.Empty))
            {
                MessageBox.Show("You must fill in working hour name!");
                return;
            }
            foreach (WorkingHourItem item in listOfWHItems)
            {
                if (item.WorkingHourName == txtWHName.Text)
                {
                    MessageBox.Show("The working hours' name has already existed!");
                    return;
                }
            }

            // Get the new WorkingHourID for new WorkingHour
            int newId = 0;
            if (listOfWHItems.Count > 0)
            {
                newId = listOfWHItems.Last().WorkingHourID + 1;
            }

            if (optCopy.Checked)
            {
                WHI = new WorkingHourItem((WorkingHourItem)cbWH.SelectedItem, txtWHName.Text, newId);
            }
            else
            {
                WHI = new WorkingHourItem(txtWHName.Text, newId);
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void NewWHDlg_Load(object sender, EventArgs e)
        {
            cbWH.Items.AddRange(listOfWHItems.ToArray());
            //coding
            try
            {
                cbWH.SelectedIndex = 0;
            }
            catch (Exception)
            {
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
